package com.example.demo;

public class AddTwoNumbers {

    public static void main(String[] args) {
        String num = "807";
        for (int i = 0; i < num.length(); i++) {
            System.out.println(num.charAt(i));

        }
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        while (l1!=null){
            l1 = l1.next;
            stringBuilder.append(l1);

        }
        while (l2!=null){
            l2 = l2.next;
            stringBuilder2.append(l2);
        }
        String num =String.valueOf(Integer.parseInt(stringBuilder.toString())+Integer.parseInt(stringBuilder2.toString())) ;
        System.out.println(num);
        ListNode temp = new ListNode();
        temp.val =num.charAt(0);
        for (int i = 1; i < num.length(); i++) {
            ListNode temp2 = new ListNode();
            temp2.val = num.charAt(i);
            temp.next = temp2;
        }
         return temp;
    }
     public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }

}
